/**
 * 
 */
package dms.presentation.form.teacher;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import dms.dto.StudentAffairTeacherDTO;
import dms.model.role.wrapper.StudentAffairTeacherWrapper;
import dms.util.ContextUtil;
import dms.util.PasswordUtil;

/**
 * @author 李健
 *
 */
public class ModifyInfoForm extends StudentAffairTeacherDTO {
	/**
	 * 
	 */
	private static final long serialVersionUID = -1520377879017556652L;

	@Override
	public ActionErrors validate(ActionMapping arg0, HttpServletRequest request) {
		ActionErrors errors = new ActionErrors();
		
		StudentAffairTeacherWrapper wrapper = (StudentAffairTeacherWrapper) ContextUtil.getContext().getBean("studentAffairTeacherWrapper");
		String email = wrapper.getStudentAffairTeacher().getAccount().getEmail();
		String password = wrapper.getStudentAffairTeacher().getAccount().getPassword();
		if(this.oldEmail != null && email != null) {
			if (this.oldEmail.length() > 0 && this.email.length() > 0) {
				if (!this.oldEmail.equals(email)) {
					errors.add("error", new ActionMessage("邮件地址填写有误", false));
				}
			}
		}
			
		if (this.oldPassword != null && this.password != null) {		
			if (this.oldPassword.length() > 0 && this.password.length() > 0) {
				String oldPassword = PasswordUtil.MD5Digest(this.oldPassword); 
				if (!oldPassword.equals(password)) {
					errors.add("error", new ActionMessage("密码不一致", false));
				}
			}
		}
			
		return errors;
	}
}
